home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  2.2 KB  |  117 lines

  1. package symantec.itools.util;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Event;
  5.  
  6. public class Timer implements Runnable {
  7.    Component target;
  8.    int eventType;
  9.    boolean repeat;
  10.    boolean repeating;
  11.    boolean execute;
  12.    Thread thread;
  13.    int delay;
  14.  
  15.    public Timer(Component var1) {
  16.       this(var1, 1000);
  17.    }
  18.  
  19.    public Timer(Component var1, int var2) {
  20.       this(var1, var2, false);
  21.    }
  22.  
  23.    public Timer(Component var1, int var2, boolean var3) {
  24.       this(var1, var2, var3, 1001);
  25.    }
  26.  
  27.    public Timer(Component var1, int var2, boolean var3, int var4) {
  28.       this.target = var1;
  29.       this.delay = var2;
  30.       this.repeat = var3;
  31.       this.execute = false;
  32.       this.thread = new Thread(this);
  33.       this.eventType = var4;
  34.       this.thread.start();
  35.    }
  36.  
  37.    public void setEventType(int var1) {
  38.       this.eventType = var1;
  39.    }
  40.  
  41.    public int getEventType() {
  42.       return this.eventType;
  43.    }
  44.  
  45.    public void setTarget(Component var1) {
  46.       this.target = var1;
  47.    }
  48.  
  49.    public Component getTarget() {
  50.       return this.target;
  51.    }
  52.  
  53.    public void setDelay(int var1) {
  54.       this.delay = var1;
  55.    }
  56.  
  57.    public int getDelay() {
  58.       return this.delay;
  59.    }
  60.  
  61.    public void start() {
  62.       this.execute = true;
  63.       this.thread.resume();
  64.    }
  65.  
  66.    public void setRepeat(boolean var1) {
  67.       this.repeat = var1;
  68.    }
  69.  
  70.    public boolean getRepeat() {
  71.       return this.repeat;
  72.    }
  73.  
  74.    public void start(int var1) {
  75.       this.delay = var1;
  76.       this.start();
  77.    }
  78.  
  79.    public void start(boolean var1) {
  80.       this.repeat = var1;
  81.       this.start();
  82.    }
  83.  
  84.    public void start(int var1, boolean var2) {
  85.       this.delay = var1;
  86.       this.repeat = var2;
  87.       this.start();
  88.    }
  89.  
  90.    public void stop() {
  91.       this.execute = false;
  92.       this.repeating = false;
  93.    }
  94.  
  95.    public void run() {
  96.       if (!this.execute) {
  97.          this.thread.suspend();
  98.       }
  99.  
  100.       try {
  101.          while(true) {
  102.             this.repeating = this.repeat;
  103.  
  104.             do {
  105.                Thread.sleep((long)this.delay);
  106.                if (this.execute) {
  107.                   this.target.handleEvent(new Event(this, this.eventType, (Object)null));
  108.                }
  109.             } while(this.repeating);
  110.  
  111.             this.thread.suspend();
  112.          }
  113.       } catch (InterruptedException var1) {
  114.       }
  115.    }
  116. }
  117.